package com.iter.devbox.cassandra;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.core.CassandraTemplate;

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.datastax.driver.core.querybuilder.Select;

public class CassandraApp {

	private static final Logger LOG = LoggerFactory.getLogger(CassandraApp.class);

	private static Cluster cluster;
	
	private static Session session;

	public static void main(String[] args) {
		try {
			cluster = Cluster.builder().addContactPoints("127.0.0.1").build();
			session = cluster.connect();

			CassandraOperations cassandraOps = new CassandraTemplate(session);
			cassandraOps.insert(new Student(2, "David", 40));

			Select s = QueryBuilder.select().from("student");
			s.where(QueryBuilder.eq("id", "2"));

			LOG.info("result：" + cassandraOps.queryForObject(s, Student.class).getId());

			//cassandraOps.truncate("person");
		} catch (Throwable e) {
			e.printStackTrace();
		}
	}
}